package org.example.Utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

public class MybatisUtils {
      static Reader reader;

     static {
        String res="mybatis-config.xml";
        try {
            reader= Resources.getResourceAsReader(res);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static SqlSession getSqlSession(){
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(reader);
        return build.openSession();
    }
}
